﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var renderTable;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form', 'util', 'laydate'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , util = layui.util
                , laydate = layui.laydate;;

            laydate.render({
                elem: '#creationTime'
                , range: true
            });

            $.getJSON("/Console/MT5Deal/GetActions", function (result) {
                let plat = result.data;
                $('#transactionType').append(new Option(top.lang.pleaseSelect, ""));
                plat.forEach(function (v) {
                    $('#transactionType').append(new Option(v, v));
                });
                layui.form.render("select");
            });
            $.getJSON("/Console/MT5Deal/GetSymbols", function (result) {
                let plat = result.data;
                $('#tradingVariety').append(new Option(top.lang.pleaseSelect, ""));
                plat.forEach(function (v) {
                    $('#tradingVariety').append(new Option(v, v));
                });
                layui.form.render("select");
            });

            renderTable = function () {
                table.render({
                    elem: '#table-datalist-MT5Deal'
                    , id: "tableReload"
                    , url: '/Console/MT5Deal/GetListJson'
                    , toolbar: false
                    , defaultToolbar: false
                    , limit: 20
                    , title: '数据表'
                    , where: {
                        login: $("#Login").val()
                    }
                    , cols: [[
                        { field: 'index', title: '序号', type: 'numbers', width: 60, templet: '#MT5DealIndex' }
                        , {
                            field: 'fullName', title: '姓名', templet: function (res) {
                                return res.fullName;
                            }
                        }
                        , {
                            field: 'CRMAccount', title: 'CRM账户', templet: function (res) {
                                return res.loginName;
                            }
                        }
                        , { field: 'tradingAccount', title: '交易账号' }
                        , {
                            field: 'transactionOrderNumber', title: '交易订单号', templet: function (res) {
                                return res.orderNumber;
                            }
                        }
                        , { field: 'tradingVariety', title: '交易品种' }
                        , { field: 'transactionType', title: '交易类型' }
                        , {
                            field: 'tradingHours', title: '交易时间', width: 180, templet: function (res) {
                                if (res.timeSetup <= 0) {
                                    return ""
                                }
                                else {
                                    return formatTime(res.tradingHours, 'Y-M-D h:m:s')
                                }
                            }
                        }
                        , { field: 'transactionPrice', title: '交易价格' }
                        , { field: 'volume', title: '交易量' }
                        , { field: 'profit', title: '利润' }
                        , { field: 'storage', title: '库存' }
                        , { field: 'profitAndLoss', title: '盈亏' }
                        , { field: 'pricePosition', title: '平仓价格' }
                    ]]
                    , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                    , done: function (res) {
                        if (res.count == 0) {
                            $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                        }
                        layer.closeAll('loading');
                        /**多语言初始化 */
                        top.SetListPageLanguage(layui);
                    }
                });
            };
            //加载表格
            renderTable();

            form.on('submit(MT5PositionSearch)', function (data) {
                //执行重载
                table.reload('tableReload', {
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                    , where: {
                        login: $("#Login").val(),
                        orderNumber: $("#orderNumber").val(),
                        transactionType: $("#transactionType").val(),
                        tradingVariety: $("#tradingVariety").val(),
                        creationTime: $("#creationTime").val()
                    }
                });
            });
            //重置
            form.on('submit(MT5PositionResetting)', function (data) {
                //执行重载
                $("#divMT5Deal input").each(function () {
                    $(this).val("");
                });
                $('#transactionType').val("");
                $('#tradingVariety').val("");
                layui.form.render("select");
            });
            //刷新
            form.on('submit(MT5PositionRefresh)', function (data) {
                //执行重载
                table.reload('tableReload', {
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                    , where: {
                        login: $("#Login").val(),
                        orderNumber: $("#orderNumber").val(),
                        transactionType: $("#transactionType").val(),
                        tradingVariety: $("#tradingVariety").val(),
                        creationTime: $("#creationTime").val()
                    }
                });
            });
        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" lay-filter="component-form-element">
                <div id="divMT5Deal" class="layui-card-body layui-form layui-form-pane" style="padding: 15px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" lay-event="tradingAccountNo">交易账号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="Login" name="Login" placeholder="tradingAccountNo" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" lay-event="orderNumber">订单号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="orderNumber" name="orderNumber" placeholder="orderNumber" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" lay-event="transactionType">交易类型</label>
                            <div class="layui-input-inline">
                                <select name="transactionType" id="transactionType">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" lay-event="tradingVariety">交易品种</label>
                            <div class="layui-input-inline">
                                <select name="tradingVariety" id="tradingVariety">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" lay-event="creationTime">创建时间</label>
                            <div class="layui-input-inline">
                                <input type="text" id="creationTime" name="creationTime" placeholder="creationTime" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="text-align:center;">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="MT5PositionSearch" lay-event="search">搜索</button>
                            <button class="layui-btn layui-btn-warm" lay-submit lay-filter="MT5PositionResetting" lay-event="resetting">重置</button>
                            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="MT5PositionRefresh" lay-event="refresh">刷新</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-hide" id="table-datalist-MT5Deal" lay-filter="table-datalist-MT5Deal"></table>
                    <script type="text/html" id="MT5DealIndex">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>